package avicit.im.lantop.basic.reportmanager.rest;


import avicit.im.lantop.basic.libstructuredefine.action.rest.LantopArchiveRest;
import avicit.im.lantop.basic.reportmanager.domain.LantopReportConfigDetails;
import avicit.im.lantop.basic.reportmanager.domain.LantopReportTemplate;
import avicit.im.lantop.basic.reportmanager.service.ReportManagerServices;
import avicit.im.lantop.basic.reportmanager.service.api.ReportManagerServicesApi;
import avicit.platform6.commons.utils.web.TreeNode;
import avicit.platform6.core.context.ThreadContextHelper;
import avicit.platform6.core.dao.Paging;
import avicit.platform6.core.domain.BeanBase;
import avicit.platform6.core.rest.msg.ResponseMsg;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "ReportManagerServices", description = "ReportManagerServices")
@RequestMapping("/api/avicit/im/lantop/basic/reportmanager/rest/ReportManagerServicesRest")
public class ReportManagerServicesRest {


    private static final Logger LOGGER = LoggerFactory.getLogger(ReportManagerServicesRest.class);


    @Resource
    private ReportManagerServices services;


    @Resource
    private ReportManagerServices reportManagerServices;

    /**
     *查找模板实际输出字段列表
     * @param map
     * @return
     */
    @PostMapping("/findReportSetField")
    @ApiOperation(value = "查找模板实际输出字段列表")
    public ResponseMsg<List<Map<String, Object>>> findReportSetField(@ApiParam(value = "查找模板实际输出字段列表", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            Map<String, String> argsMaps = (Map<String, String>) map.get("argsMaps");
            List<Map<String, Object>> reportSetField = services.findReportSetField(argsMaps);
            responseMsg.setResponseBody(reportSetField);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 查询DataSource数据表
     * @param map
     * @return
     */
    @PostMapping("/findDataSource")
    @ApiOperation(value = "查询DataSource数据表")
    public ResponseMsg<List<Map<String, Object>>> findDataSource(@ApiParam(value = "查询DataSource数据表", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            Map<String, String> argsMaps = (Map<String, String>) map.get("argsMaps");
            List<Map<String, Object>> dataSource = services.findDataSource(argsMaps);
            responseMsg.setResponseBody(dataSource);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 模板id查询报表配置
     * @param map
     * @return
     */
    @PostMapping("/findLantopReportConfigByTemplateId")
    @ApiOperation(value = "模板id查询报表配置")
    public ResponseMsg<List<Map<String, Object>>> findLantopReportConfigByTemplateId(@ApiParam(value = "模板id查询报表配置", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            String reportId = (String) map.get("reportId");
            List<Map<String, Object>> lantopReportConfigByTemplateId = services.findLantopReportConfigByTemplateId(reportId);
            responseMsg.setResponseBody(lantopReportConfigByTemplateId);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 根据报表ID查找Name
     * @param map
     * @return
     */
    @PostMapping("/getReportRealNameById")
    @ApiOperation(value = "根据报表ID查找Name")
    public ResponseMsg<String> getReportRealNameById(@ApiParam(value = "根据报表ID查找Name", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        try {
            String reportId = (String) map.get("reportId");
            String reportRealNameById = services.getReportRealNameById(reportId);
            responseMsg.setResponseBody(reportRealNameById);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 根据表ID和数据节点ID获取二维码规则信息
     * @param map
     * @return
     */
    @PostMapping("/findRuleInfoByTableId")
    @ApiOperation(value = "根据表ID和数据节点ID获取二维码规则信息")
    public ResponseMsg<List<Map<String, Object>>> findRuleInfoByTableId(@ApiParam(value = "根据表ID和数据节点ID获取二维码规则信息", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            String tableNameIds = (String) map.get("tableNameIds");
            String nodeId = (String) map.get("nodeId");
            List<Map<String, Object>> ruleInfoByTableId = services.findRuleInfoByTableId(tableNameIds, nodeId);
            responseMsg.setResponseBody(ruleInfoByTableId);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    @PostMapping("/findRuleInfoByTableId/v1")
    @ApiOperation(value = "根据表ID和数据节点ID获取二维码规则信息")
    public ResponseMsg<List<Map<String, Object>>> findRuleInfoByTableId1(@ApiParam(value = "根据表ID和数据节点ID获取二维码规则信息", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            String tableNameIds = (String) map.get("tableNameIds");
            List<Map<String, Object>> ruleInfoByTableId = services.findRuleInfoByTableId(tableNameIds);
            responseMsg.setResponseBody(ruleInfoByTableId);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 保存报表临时数据表信息
     * @param map
     * @return
     */
    @PostMapping("/saveReportTemplate")
    @ApiOperation(value = "保存报表临时数据表信息")
    public ResponseMsg<String> saveReportTemplate(@ApiParam(value = "保存报表临时数据表信息", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        try {
            LantopReportTemplate temp = (LantopReportTemplate) map.get("temp");
            String s = services.saveReportTemplate(temp);
            responseMsg.setResponseBody(s);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 删除树节点
     * @param map
     * @return
     */
    @PostMapping("/deleteLantopReportTree")
    @ApiOperation(value = "删除树节点")
    public ResponseMsg<Boolean> deleteLantopReportTree(@ApiParam(value = "删除树节点", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        try {
            Map<String,Object> paramsMap = (Map<String, Object>) map.get("paramsMap");
            boolean b = services.deleteLantopReportTree(paramsMap);
            responseMsg.setResponseBody(b);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     *递归查询树结构
     * @param map
     * @return
     */
    @PostMapping("/getTreeExerciseByParentId")
    @ApiOperation(value = "递归查询树结构")
    public ResponseMsg<List<TreeNode>> getTreeExerciseByParentId(@ApiParam(value = "递归查询树结构", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<List<TreeNode>> responseMsg = new ResponseMsg<>();
        try {
            String id = (String) map.get("id");
            String orgId = (String) map.get("orgId");
            String orgIdentity = (String) map.get("orgIdentity");
            Integer level = (Integer) map.get("level");
            String contextPath = (String) map.get("contextPath");
            List<TreeNode> treeExerciseByParentId = services.getTreeExerciseByParentId(id, orgId, orgIdentity, level, contextPath);
            responseMsg.setResponseBody(treeExerciseByParentId);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 插入模板树数据
     * @param map
     * @return
     */
    @PostMapping("/insertIntoLantopReportTree")
    @ApiOperation(value = "插入模板树数据")
    public ResponseMsg<Boolean> insertIntoLantopReportTree(@ApiParam(value = "插入模板树数据", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        try {
            Map<String,Object> param = (Map<String, Object>) map.get("param");
            boolean b = services.insertIntoLantopReportTree(param);
            responseMsg.setResponseBody(b);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 通过配置表名，查找已配置过的模板树
     * @param map
     * @return
     */
    @PostMapping("/findTreeByTableName")
    @ApiOperation(value = "通过配置表名，查找已配置过的模板树")
    public ResponseMsg<List<TreeNode>> findTreeByTableName(@ApiParam(value = "通过配置表名，查找已配置过的模板树", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<List<TreeNode>> responseMsg = new ResponseMsg<>();
        try {
            Map<String,Object> paramsMap = (Map<String, Object>) map.get("paramsMap");
            List<TreeNode> treeByTableName = services.findTreeByTableName(paramsMap);
            responseMsg.setResponseBody(treeByTableName);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 删除模块对应关系
     * @param map
     * @return
     */
    @PostMapping("/deleteReportRelation")
    @ApiOperation(value = "删除模块对应关系")
    public ResponseMsg deleteReportRelation(@ApiParam(value = "删除模块对应关系", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            String reportId = (String) map.get("reportId");
            String tableName = (String) map.get("tableName");
            String orgId = (String) map.get("orgId");
            services.deleteReportRelation(reportId, tableName, orgId);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 通过id获取报表临时表数据
     * @param map
     * @return
     */
    @PostMapping("/getLantopReportTemplateById")
    @ApiOperation(value = "通过id获取报表临时表数据")
    public ResponseMsg getLantopReportTemplateById(@ApiParam(value = "通过id获取报表临时表数据", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            String tempId = (String) map.get("tempId");
            LantopReportTemplate lantopReportTemplateById = services.getLantopReportTemplateById(tempId);
            responseMsg.setResponseBody(lantopReportTemplateById);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 保存DataBase数据
     * @param map
     * @return
     */
    @PostMapping("/saveDataBaseConfigForTable")
    @ApiOperation(value = "保存DataBase数据")
    public ResponseMsg<Boolean> saveDataBaseConfigForTable(@ApiParam(value = "保存DataBase数据", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        try {
            Map<String,Object> paramsMap = (Map<String, Object>) map.get("paramsMap");
            boolean b = services.saveDataBaseConfigForTable(paramsMap);
            responseMsg.setResponseBody(b);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 查找来源于数据库模板应输出字段
     * @param map
     * @return
     */
    @PostMapping("/findDataSourceFields")
    @ApiOperation(value = "查找来源于数据库模板应输出字段")
    public ResponseMsg<List<String>> findDataSourceFields(@ApiParam(value = "查找来源于数据库模板应输出字段", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<List<String>> responseMsg = new ResponseMsg<>();
        try {
            Map<String,Object> paramsMap = (Map<String, Object>) map.get("paramsMap");
            String reportId = (String) map.get("reportId");
            List<String> dataSourceFields = services.findDataSourceFields(reportId, paramsMap);
            responseMsg.setResponseBody(dataSourceFields);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 插入模板树数据
     * @param map
     * @return
     */
    @PostMapping("/insertIntoLantopReportTreeForUpload")
    @ApiOperation(value = "插入模板树数据")
    public ResponseMsg<List<Map<String, Object>>> insertIntoLantopReportTreeForUpload(@ApiParam(value = "插入模板树数据", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            String nodeId = (String) map.get("nodeId");
            String orgId = (String) map.get("orgId");
            List<Map<String, Object>> tablesByNodeId = reportManagerServices.findTablesByNodeId(nodeId, orgId);
            responseMsg.setResponseBody(tablesByNodeId);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 插入模板树数据
     * @param map
     * @return
     */
    @PostMapping("/findTablesByNodeId")
    @ApiOperation(value = "通过报表模板id查询报表配置规则主表")
    public ResponseMsg<String> findTablesByNodeId(@ApiParam(value = "通过报表模板id查询报表配置规则主表", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        try {
            String templateId = (String) map.get("templateId");
            String lantopReportConfigurationByTemplateId = reportManagerServices.findLantopReportConfigurationByTemplateId(templateId);
            responseMsg.setResponseBody(lantopReportConfigurationByTemplateId);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    @PostMapping("/saveLantopReportConfiguration")
    @ApiOperation(value = "通过报表模板id查询报表配置规则主表")
    public ResponseMsg saveLantopReportConfiguration(@ApiParam(value = "通过报表模板id查询报表配置规则主表", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            BeanBase dto = (BeanBase) map.get("dto");
            reportManagerServices.saveLantopReportConfiguration(dto);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 报表模板配置规则保存子表
     * @param map
     * @return
     */
    @PostMapping("/saveReportConfig")
    @ApiOperation(value = "报表模板配置规则保存子表")
    public ResponseMsg saveReportConfig(@ApiParam(value = "报表模板配置规则保存子表", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            LantopReportConfigDetails lantopReportConfigDetails = (LantopReportConfigDetails) map.get("lantopReportConfigDetails");
            reportManagerServices.saveReportConfig(lantopReportConfigDetails);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 报表模板配置规则更新子表
     * @param map
     * @return
     */
    @PostMapping("/updateReportConfig")
    @ApiOperation(value = "报表模板配置规则更新子表")
    public ResponseMsg updateReportConfig(@ApiParam(value = "报表模板配置规则更新子表", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            LantopReportConfigDetails lantopReportConfigDetails = (LantopReportConfigDetails) map.get("lantopReportConfigDetails");
            reportManagerServices.updateReportConfig(lantopReportConfigDetails);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     *
     * @param map
     * @return
     */
    @PostMapping("/findLantopReportConfigurationIdById")
    @ApiOperation(value = "通过子表id查询主表")
    public ResponseMsg<String> findLantopReportConfigurationIdById(@ApiParam(value = "通过子表id查询主表", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        try {
            String s = (String) map.get("s");
            String lantopReportConfigurationIdById = reportManagerServices.findLantopReportConfigurationIdById(s);
            responseMsg.setResponseBody(lantopReportConfigurationIdById);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     *报表模板配置规则子表根据id删除数据
     * @param map
     * @return
     */
    @PostMapping("/deleteReportConfigByIds")
    @ApiOperation(value = "报表模板配置规则子表根据id删除数据")
    public ResponseMsg deleteReportConfigByIds(@ApiParam(value = "报表模板配置规则子表根据id删除数据", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            String ids = (String) map.get("ids");
            reportManagerServices.deleteReportConfigByIds(ids);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 通过主表id查询子表数据个数
     * @param map
     * @return
     */
    @PostMapping("/findLantopReportConfigDetailsByPid")
    @ApiOperation(value = "通过主表id查询子表数据个数")
    public ResponseMsg<Integer> findLantopReportConfigDetailsByPid(@ApiParam(value = "通过主表id查询子表数据个数", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<Integer> responseMsg = new ResponseMsg<>();
        try {
            String reportConfigPid = (String) map.get("reportConfigPid");
            int lantopReportConfigDetailsByPid = reportManagerServices.findLantopReportConfigDetailsByPid(reportConfigPid);
            responseMsg.setResponseBody(lantopReportConfigDetailsByPid);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 根据id删除报表模板配置规则主表
     * @param map
     * @return
     */
    @PostMapping("/deleteLantopReportConfigurationById")
    @ApiOperation(value = "根据id删除报表模板配置规则主表")
    public ResponseMsg deleteLantopReportConfigurationById(@ApiParam(value = "根据id删除报表模板配置规则主表", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            String reportConfigPid = (String) map.get("reportConfigPid");
            reportManagerServices.deleteLantopReportConfigurationById(reportConfigPid);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 报表模板配置规则子表查询
     * @param map
     * @return
     */
    @PostMapping("/getReportConfig")
    @ApiOperation(value = "报表模板配置规则子表查询")
    public ResponseMsg<Paging<LantopReportConfigDetails>> getReportConfig(@ApiParam(value = "报表模板配置规则子表查询", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<Paging<LantopReportConfigDetails>> responseMsg = new ResponseMsg<>();
        try {
            Paging<LantopReportConfigDetails> page = (Paging<LantopReportConfigDetails>) map.get("page");
            Map<String, Object> tMap = (Map<String, Object>) map.get("tMap");
            Paging<LantopReportConfigDetails> reportConfig = reportManagerServices.getReportConfig(page, tMap);
            responseMsg.setResponseBody(reportConfig);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }



    @PostMapping("/recurFindTreeNodesByParentId")
    @ApiOperation(value = "报表模板配置规则子表查询")
    public ResponseMsg<List<TreeNode>> recurFindTreeNodesByParentId(@ApiParam(value = "报表模板配置规则子表查询", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<List<TreeNode>> responseMsg = new ResponseMsg<>();
        try {
            Integer level = (Integer) map.get("level");
            String id = (String) map.get("id");
            String orgId = (String) map.get("orgId");
            List<TreeNode> treeNodes = reportManagerServices.recurFindTreeNodesByParentId(id, level, orgId);
            responseMsg.setResponseBody(treeNodes);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    @PostMapping("/getPublicFieldInfo")
    @ApiOperation(value = "报表模板配置规则子表查询")
    public ResponseMsg<List<Map<String, Object>>> getPublicFieldInfo(@ApiParam(value = "报表模板配置规则子表查询", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            List<Map<String, Object>> publicFieldInfo = reportManagerServices.getPublicFieldInfo();
            responseMsg.setResponseBody(publicFieldInfo);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 根据模板ID删除其对应的字段配置信息
     * @param map
     * @return
     */
    @PostMapping("/deleteFieldInfosById")
    @ApiOperation(value = "根据模板ID删除其对应的字段配置信息")
    public ResponseMsg<Boolean> deleteFieldInfosById(@ApiParam(value = "根据模板ID删除其对应的字段配置信息", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        try {
            Map<String,Object> paramsMap = (Map<String, Object>) map.get("paramsMap");
            boolean b = services.deleteFieldInfosById(paramsMap);
            responseMsg.setResponseBody(b);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 保存用户自定义数据源
     * @param map
     * @return
     */
    @PostMapping("/saveUseCustomDataSource")
    @ApiOperation(value = "保存用户自定义数据源")
    public ResponseMsg<Boolean> saveUseCustomDataSource(@ApiParam(value = "保存用户自定义数据源", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        try {
            Map<String,Object> paramsMap = (Map<String, Object>) map.get("paramsMap");
            boolean b = services.saveUseCustomDataSource(paramsMap);
            responseMsg.setResponseBody(b);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 查找用户自定义数据源应输出字段
     * @param map
     * @return
     */
    @PostMapping("/findUseCustomDataSourceFields")
    @ApiOperation(value = "查找用户自定义数据源应输出字段")
    public ResponseMsg<List<String>> findUseCustomDataSourceFields(@ApiParam(value = "查找用户自定义数据源应输出字段", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<List<String>> responseMsg = new ResponseMsg<>();
        try {
            Map<String,Object> paramsMap = (Map<String, Object>) map.get("paramsMap");
            String reportId = (String) map.get("reportId");
            List<String> useCustomDataSourceFields = services.findUseCustomDataSourceFields(reportId, paramsMap);
            responseMsg.setResponseBody(useCustomDataSourceFields);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 根据模板ID查找其对应的字段配置信息
     * @param map
     * @return
     */
    @PostMapping("/findFieldInfosByReportid")
    @ApiOperation(value = "根据模板ID查找其对应的字段配置信息")
    public ResponseMsg<List<String>> findFieldInfosByReportid(@ApiParam(value = "根据模板ID查找其对应的字段配置信息", name = "map") @RequestBody Map<String, Object> map) {
        ResponseMsg<List<String>> responseMsg = new ResponseMsg<>();
        try {
            Map<String,Object> paramsMap = (Map<String, Object>) map.get("paramsMap");
            Page<Map<String, Object>> page = (Page<Map<String, Object>>) map.get("page");
            services.findFieldInfosByReportid(paramsMap, page);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


}
